<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <!--        type 0 学生 2 职工-->
        <span>{{ type == 0 ? '学生' : '教职工' }}健康申报历史记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="hearder-search">
          <div class="breadcrumb-container">
            <div class="search_box">
              <component
                  v-bind:is="item.propertyType"
                  :property.sync="item"
                  v-for="(item, index) in getPower"
                  :key="index"
                  @updateVal="updateVal"
              ></component>
<!--              healthname-->
              <el-input v-model="searWord.realname" placeholder="姓名" size="small"
                        class="w-100" v-if="Number(this.type) == 1"></el-input>
              <el-input v-model="searWord.name" placeholder="姓名" size="small"
                        class="w-100" v-else></el-input>
              <el-select placeholder="身体状况" v-model="searWord.is_health" size="small" class="w-140">
                <el-option :label="item.name" :value="item.id" v-for="(item, index) in isHealth"
                           :key="index"></el-option>
              </el-select>
              <el-select placeholder="核酸或抗原检测" v-model="searWord.is_nuclein" size="small" class="w-200">
                <el-option :label="item.name" :value="item.id" v-for="(item, index) in isHealthOther"
                           :key="index"></el-option>
              </el-select>
              <el-date-picker
                  v-model="value1"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  size="small"
                  :picker-options="pickerOptions1">
              </el-date-picker>
              <el-button type="primary" size="small" @click="searchFn('search')"><i class="el-icon-search"></i>搜索
              </el-button>
              <el-button size="small" @click="searchFn('refresh')"><i class="el-icon-refresh"></i>重置刷新</el-button>
            </div>
          </div>
        </div>
        <div class="breadcrumb-container">
          <downexcel type="morningList" :option="searWord"></downexcel>
          <span class="allbook">总 {{ page.total }} 条数据</span>
        </div>
        <!--本体列表，数据 -->
        <div class="table-body">
          <div class="table-body-box">
            <el-table
                ref="multipleTable"
                :data="arryList"
                :stripe="tableStripe"
                :border="tableBorder"
                :height="tableHeight"
                tooltip-effect="dark"
                style="width: 100%"
                header-cell-class-name="table-text-c"
                cell-class-name="table-text-c">
              <el-table-column
                  prop="name"
                  label="姓名">
                <template slot-scope="scope">
                  <!--                  type 0 学生 1 职工-->
                  {{ type == 0 ? scope.row.student.name : scope.row.user.realname }}
                </template>
              </el-table-column>
              <el-table-column
                  prop="create_time"
                  label="申报日期"
                  width="160">
              </el-table-column>
              <el-table-column
                  prop="temperature"
                  label="体温（°C）">
                <template slot-scope="scope">
                  <span :style="{'color':Number(scope.row.temperature)>37.3?'red':''}">{{
                      scope.row.temperature
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  prop="description"
                  label="学生本人身体状况">
                <template slot-scope="scope">
                  <span :style="{'color':scope.row.is_health!==1?'red':''}">{{ scope.row.is_health==1?'正常':'发热、咳嗽、乏力、咽痛、流涕、腹泻、肌肉酸痛等症状' }}</span>
                </template>
              </el-table-column>
              <el-table-column
                  prop="description"
                  label="是否有进行核酸或者抗原检测">
                <template slot-scope="scope">
                  <span>{{ scope.row.is_green==1?'是':'否' }}</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
    <!--    type 1 学生 2 职工-->
    <healthEdit :visible.sync="healthdetailvisible" :healthId="healthId" :type="type==0?1:2"></healthEdit>
  </div>
</template>

<script>
import {pagination, yearDay} from '@/utils/util.js'
import healthEdit from "./healthEdit";
export default {
  props: ['visible', 'type'], // commoent 学生点评 collection 学生采集
  components: {
    healthEdit
  },
  data() {
    return {
      healthdetailvisible: false,
      healthId: 0,
      dialogVisible: false,
      tableStripe: true, // 是否斑马栏
      tableBorder: true, // 单元格右边边框
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '班级', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      },
      // 搜索
      searWord: {
        is_health: '', // 是否绿吗
        is_nuclein: '',
        start_time: '',
        end_time: '',
        type: this.type,
        class_id: '',
        section_id: '',
      },
      tableHeight: 0,
      value1: '',
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now() + 8.64e7
        }
      },
      // 是否健康
      isHealth: [
        {
          id: 1,
          name: '正常'
        },
        {
          id: 0,
          name: '不正常'
        }
      ],
      isHealthOther: [
        {
          id: 1,
          name: '是'
        },
        {
          id: 0,
          name: '否'
        }
      ],
      temperatureList: [
        {
          id: 1,
          name: '是'
        },
        {
          id: 0,
          name: '否'
        }
      ]
    }
  },
  watch: {
    visible() {
      if (this.visible) {
        let n = this;
        if (Number(this.type) === 1) {
          this.$set(this.searWord, 'realname', '')
        }else{
          this.$set(this.searWord, 'name', '')
        }
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 20 + 50 + 50 + 60 + 51)
          console.log('height:', height,  this.searWord)
        })
        this.InitFn()
      } else {
        this.arryList = [];
        this.clearWord()
      }
      this.dialogVisible = this.visible
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 初始化
    async InitFn() {
      let option = this.getJson(this.searWord)
      option.p = this.page.pageindex
      let data = await this.$fetch(this.api.manage.health.index, option);
      if (!data.code) {
        for (let i in data.list.data) {
          data.list.data[i].create_time = yearDay(data.list.data[i].create_time)
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
      }
    },
    // 搜索组件
    searchFn(option) {
      this.page.pageindex = 1
      if (option === 'refresh') {
        this.clearWord()
      } else {
        if (this.value1) {
          this.searWord.start_time = this.value1[0]
          this.searWord.end_time = this.value1[1]
        } else {
          this.searWord.start_time = '';
          this.searWord.end_time = '';
        }
      }
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    clearWord() {
      let getPower = this.getJson(this.getPower)
      getPower.section_id.valueText = ''
      getPower.section_id.child[0].valueText = ''
      this.getPower = this.getJson(getPower)

      this.value1 = []
      this.healthname = ''
      this.searWord.start_time = ''
      this.searWord.end_time = ''
      if (Number(this.type) === 1) {
        this.searWord.realname = ''
      }else{
        this.searWord.name = ''
      }
      this.searWord.is_green = ''
      this.searWord.is_other_green = ''
      this.searWord.is_temperature = ''
    },
    addActive(id) {
      this.healthId = id;
      this.healthdetailvisible = true;
      // this.$router.push('/healthEdit?id=' + id)
    },
    // 更新值
    updateVal(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.searWord[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.searWord[option.select[i].name] = option.select[i].valueText
          } else {
            this.searWord[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 90%;
  height: 80%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.hearder-search {
  display: flex;
  align-items: center;
}
.breadcrumb-container{
  margin-bottom: 10px;
}
</style>


